<template>
	<view>
		<cu-custom :bgLiner="true" :isBlack="false">
			<block slot="content">点餐记录</block>
		</cu-custom>
		<view class="contents">
			<view class="voucher-item m-b-10" v-for="(item,index) in list" :key="index" @click="toDetail(item)">
				<view class="flex justify-space-between align-center">
					<view class="f-16 fontBold orange">
						{{item.name}}
					</view>
					<!-- accept_orders` tinyint(1) DEFAULT '0' COMMENT '0支付后待商家处理 1接单 2拒绝 3完成', -->
					<!-- 0全部 1待处理 1已接单 2已拒绝 -->
					<view class="f-16 fontBold yellow">
						{{item.accept_orders==1?'已接单':item.accept_orders==2?'已拒绝':item.accept_orders==3?'已完成':'待处理'}}
					</view>
				</view>
				<view class=" flex m-t-10">
					<view class="flex align-center">
						<image :src="item.cover?item.cover.split(',')[0]:''" class="imgs"></image>
					</view>
					<view class="flex-1 p-l-10 flex flex-direction justify-space-between">
						<view class="f-13 m-b-3">
							{{item.goods_strs}}
						</view>
						<view class="f-13 m-b-3">
							用餐人数：{{item.user_num}}人
						</view>
						<view class="">
							<view class="flex  m-b-3">
								<view class="f-13 ">
									用餐时间：{{item.book_at}}
								</view>
							</view>
							<view class="flex justify-space-between">
								<view class="orange f-17 fontBold">
									
								</view>
								<view class="orange f-17 fontBold">
									￥{{item.total_price}}
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="nodata" v-if="list.length == 0">
				暂无数据~
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list:[],
				page:1,
				last_page:1,
			}
		},
		onLoad(option) {
			this.getList();
		},
		onReachBottom() {
			if(this.page >= this.last_page)return;
			this.page++;
			this.getList();
		},
		onShow() {
			
		},
		methods: {
			
			toDetail(item){
				uni.navigateTo({
					url:'/pages/mine/dineLog?id='+item.id
				})
			},
			getList(){
				let data = {
					page:this.page,
					type:2
				}
				this.$http('/apicloud/Order/applicationList',data).then(res=>{
					if(res.code == 200){
						let datas = res.data;
						let list = datas.list.data;
						this.last_page = datas.list.last_page;
						list.forEach(item=>{
							let len = item.goods.length;
							let arr = [];
							item.goods.forEach(item2=>{
								arr.push(item2.goods_name);
							})
							let arr2 = [];
							if(arr.length>2){
								arr2 = arr.slice(0,2);
							}else{
								arr2 = arr;
							}
							let str = arr2.join(',');
							if(len > 2){
								str = str + '等'+len+'个菜'
							}
							this.$set(item,'goods_strs',str);
						})
						if(this.page == 1){
							
							this.list = list;
						}else{
							this.list = this.list.concat(list);
						}
						
					}
				})
			},
		}
	}
</script>

<style lang="less">
	.voucher-item{
		width: 100%;
		background: #FFFFFF;
		box-shadow: 0px 0px 16px rgba(0,0,0,0.05);
		border-radius: 16rpx;
		padding: 24rpx;
		.icon{
			width: 32rpx;
			height: 28rpx;
		}
	}
	.imgs{
		width: 160rpx;
		height: 160rpx;
		border-radius: 16rpx;
	}
</style>
